package com.fr.report.core;

import com.fr.base.XMLable;
import com.fr.base.core.BaseCoreUtils;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.report.io.xml.ReportXMLUtils;
import java.util.ArrayList;
import java.util.List;

public class KV
  implements XMLable
{
  public static final String XML_TAG = "KV";
  public static final String ARRAY_XML_TAG = "KVS";
  private String key;
  private Object value;

  public KV()
  {
  }

  public KV(String paramString, Object paramObject)
  {
    this.key = paramString;
    this.value = paramObject;
  }

  public String getKey()
  {
    return this.key;
  }

  public void setKey(String paramString)
  {
    this.key = paramString;
  }

  public Object getValue()
  {
    return this.value;
  }

  public void setValue(Object paramObject)
  {
    this.value = paramObject;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str;
      if ((str = paramXMLableReader.getAttr("key")) != null)
        this.key = str;
      if ((str = paramXMLableReader.getAttr("value")) != null)
        this.value = str;
    }
    if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("O")))
      this.value = ReportXMLUtils.readObject(paramXMLableReader);
  }

  public static KV[] readKTVArray(XMLableReader paramXMLableReader)
  {
    ArrayList localArrayList = new ArrayList();
    paramXMLableReader.readXMLObject(new XMLReadable(localArrayList)
    {
      private final List val$KTVList;

      public void readXML(XMLableReader paramXMLableReader)
      {
        if (paramXMLableReader.isChildNode())
        {
          String str = paramXMLableReader.getTagName();
          if (("KV".equals(str)) || ("KTV".equals(str)))
          {
            KV localKV = new KV();
            paramXMLableReader.readXMLObject(localKV);
            this.val$KTVList.add(localKV);
          }
        }
      }
    });
    return ((KV[])localArrayList.toArray(new KV[localArrayList.size()]));
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("KV").attr("key", getKey());
    ReportXMLUtils.writeObject(paramXMLPrintWriter, this.value);
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof KV))
      return false;
    KV localKV = (KV)paramObject;
    return ((ComparatorUtils.equals(getKey(), localKV.getKey())) && (ComparatorUtils.equals(getValue(), localKV.getValue())));
  }

  public String toString()
  {
    return "[key:" + getKey() + " value:" + getValue() + "]";
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    KV localKV = (KV)super.clone();
    if (this.value != null)
      localKV.value = BaseCoreUtils.cloneObject(this.value);
    return localKV;
  }
}